.include "asm/include/battle_commands.inc"

.data

_000:
    PrintBufferedMessage 
    Wait 
    WaitButtonABTime 30
    CheckMoveHit BATTLER_CATEGORY_MSG_ATTACKER, BATTLER_CATEGORY_MSG_TEMP, BATTLER_CATEGORY_MSG_TEMP, _123
    UpdateVar OPCODE_SET, BSCRIPT_VAR_MOVE_EFFECT_CHANCE, 1
    PlayMoveAnimationOnMons BATTLER_CATEGORY_MSG_TEMP, BATTLER_CATEGORY_MSG_ATTACKER, BATTLER_CATEGORY_MSG_TEMP
    Wait 
    UpdateVar OPCODE_FLAG_OFF, BSCRIPT_VAR_BATTLE_STATUS, BATTLE_STATUS_MOVE_ANIMATIONS_OFF
    CompareMonDataToValue OPCODE_FLAG_NOT, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_STATUS2, STATUS2_SUBSTITUTE, _058
    UpdateVar OPCODE_MUL, BSCRIPT_VAR_HP_CALC, -1
    CompareMonDataToVar OPCODE_LTE, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_SUBSTITUTE_HP, BSCRIPT_VAR_HP_CALC, _044
    UpdateMonDataFromVar OPCODE_SUB, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_SUBSTITUTE_HP, BSCRIPT_VAR_HP_CALC
    GoTo _054

_044:
    UpdateMonData OPCODE_SET, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_SUBSTITUTE_HP, 0
    UpdateMonData OPCODE_FLAG_OFF, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_STATUS2, STATUS2_SUBSTITUTE

_054:
    Call BATTLE_SUBSCRIPT_HIT_SUBSTITUTE
    GoTo _092

_058:
    CheckHoldOnWith1HP BATTLER_CATEGORY_MSG_TEMP
    Call BATTLE_SUBSCRIPT_UPDATE_HP
    CompareMonDataToValue OPCODE_FLAG_NOT, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_STATUS2, STATUS2_RAGE, _092
    CompareMonDataToValue OPCODE_EQU, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_HP, 0, _092
    CompareMonDataToValue OPCODE_EQU, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_STAT_CHANGE_ATK, 12, _092
    UpdateMonData OPCODE_ADD, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_STAT_CHANGE_ATK, 1
    PlayBattleAnimation BATTLER_CATEGORY_MSG_TEMP, BATTLE_ANIMATION_STAT_BOOST
    Wait
    // {0}’s rage is building!
    PrintMessage 363, TAG_NICKNAME, BATTLER_CATEGORY_MSG_TEMP
    Wait 
    WaitButtonABTime 30

_092:
    CompareVarToValue OPCODE_FLAG_NOT, BSCRIPT_VAR_MOVE_STATUS_FLAGS, MOVE_STATUS_ENDURED_ITEM, _122
    CompareMonDataToValue OPCODE_EQU, BATTLER_CATEGORY_MSG_TEMP, BMON_DATA_ABILITY, ABILITY_STURDY, _122
    PlayBattleAnimation BATTLER_CATEGORY_MSG_TEMP, BATTLE_ANIMATION_HELD_ITEM
    Wait 
    // {0} hung on using its {1}!
    PrintMessage 912, TAG_NICKNAME_ITEM, BATTLER_CATEGORY_MSG_TEMP, BATTLER_CATEGORY_MSG_BATTLER_TEMP
    Wait 
    WaitButtonABTime 30
    CheckItemHoldEffect CHECK_OPCODE_NOT_HAVE, BATTLER_CATEGORY_MSG_TEMP, HOLD_EFFECT_ENDURE, _end
    RemoveItem BATTLER_CATEGORY_MSG_TEMP

_122:
    UpdateVarFromVar OPCODE_SET, BSCRIPT_VAR_BATTLER_TARGET, BSCRIPT_VAR_MSG_BATTLER_TEMP
    UpdateVarFromVar OPCODE_SET, BSCRIPT_VAR_BATTLER_ATTACKER, BSCRIPT_VAR_MSG_ATTACKER
    UpdateVarFromVar OPCODE_SET, BSCRIPT_VAR_PHYSICAL_DAMAGE_TAKEN, BSCRIPT_VAR_HP_CALC // allows color change to proc
    UpdateVar OPCODE_SET, BSCRIPT_VAR_MOVE_NO_CUR, MOVE_FUTURE_SIGHT
    TriggerAbilityOnHit _end
    CallFromVar BSCRIPT_VAR_TEMP_DATA
    Call BATTLE_SUBSCRIPT_SWITCH_IN_ABILITY_CHECK

_end:
    End 

_123:
    WaitButtonABTime 30
    // But it failed!
    PrintMessage 796, TAG_NONE
    Wait 
    WaitButtonABTime 30
    End 
